# -*- coding: utf-8 -*-
# @Time: 2021/11/27 23:03
# @Author: lijinxi
# @File    : average_total_delay.py
# @desc

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns

# sns.set(color_codes=True)
from matplotlib.ticker import MultipleLocator

mpl.rcParams["axes.unicode_minus"] = False

# 柱高信息
Y = [6.4985, 4.618319278836317, 1.177775]
Y1 = [3.963500000004214, 4.209828963909562, 11.0158625]
Y2 = [5.404, 8.594802764864616, 2.359875]
X = np.arange(len(Y))

bar_width = 0.2
tick_label = ['CD', 'QD', 'SD']

axes = plt.gca()
axes.set_ylim([0, 12])
plt.tick_params(labelsize=20)  # 刻度字体大小13
plt.bar(X, Y, bar_width - 0.04, align="center", color='white', edgecolor="olivedrab", label="OSS", hatch='/')
plt.bar(X + bar_width, Y1, bar_width - 0.04, color='white', edgecolor="teal", align="center", \
        label="QO", hatch='+')
plt.bar(X + bar_width * 2, Y2, bar_width - 0.04, color='white', edgecolor="royalblue", align="center", \
        label="SO", hatch='-')
ax = plt.gca()
ax.tick_params(labelsize=16)  # 刻度字体大小13
plt.ylabel("Delay (s)", fontsize=18)
plt.xlabel("Delay Type", fontsize=18)

plt.xticks(X + bar_width, tick_label)
plt.legend(fontsize=18, frameon=False)
y_major_locator = MultipleLocator(2)
ax = plt.gca()

ax.yaxis.set_major_locator(y_major_locator)
plt.axhline(y=2, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=4, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=6, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=8, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=10, color='lightgray', ls=':', linewidth=1)
plt.savefig('total_delay.pdf', bbox_inches='tight')  # 保存成PDF放大后不失真（默认保存在了当前文件夹下）
plt.show()
